# -*- coding: iso-8859-1 -*-
# file __init__.py
# author Rocco Martino
#
############################################################################
#    Copyright (C) 2015 by Rocco Martino                                   #
#    martinorocco@gmail.com                                                #
#                                                                          #
#    This program is free software; you can redistribute it and/or modify  #
#    it under the terms of the GNU Lesser General Public License as        #
#    published by the Free Software Foundation; either version 2.1 of the  #
#    License, or (at your option) any later version.                       #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU Lesser General Public License for more details.                   #
#                                                                          #
#    You should have received a copy of the GNU Lesser General Public      #
#    License along with this program; if not, write to the                 #
#    Free Software Foundation, Inc.,                                       #
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
############################################################################

############################################################################
import bpy

from bpy_extras.io_utils import ExportHelper
from bpy.props import StringProperty, IntProperty, BoolProperty, FloatProperty
############################################################################




############################################################################
# ........................................................................ #
bl_info = {
    "name"          :   "ooEngine osgt format",
    "author"        :   "Rocco Martino",
    "blender"       :   (2, 7, 0),
    "location"      :   "File > Export",
    "description"   :   "Export all scenes",
    "category"      :   "Import-Export"
}
# ........................................................................ #
############################################################################




############################################################################
# ........................................................................ #
class ExportOSGT(bpy.types.Operator, ExportHelper):





############################################################################
    bl_idname = "export_scene.osgt"
    bl_label = "Export OSGT"

    filename_ext = ".osgt"

    filter_glob = StringProperty(
                    default = "*.osgt",
                    options = {"HIDDEN"}
                )


    use_threaded_manager = BoolProperty( name="use ThreadedManager", description="handle dynamics and logics in a separate thread", default=False)
    use_viewer = BoolProperty( name="use ooViewer", description="requires ooViewer", default=False)
    use_game = BoolProperty( name="game logics", description="requires ooGame", default=True)

    max_anisotropy = IntProperty( name="max anisotropy", description="default max anisotropy" , default=4, min=0)

    erp = FloatProperty( name="joint erp", description="see ode manual" , default=0.2, min=0.0, max=1.0)
    cfm = FloatProperty( name="joint cfm", description="see ode manual" , default=0.00001, min=0.0, max=1.0)

    stop_erp = FloatProperty( name="stop erp", description="see ode manual" , default=0.2, min=0.0, max=1.0)
    stop_cfm = FloatProperty( name="stop cfm", description="see ode manual" , default=0.00001, min=0.0, max=1.0)

    soft_erp = FloatProperty( name="contact erp", description="see ode manual" , default=0.5, min=0.0, max=1.0)
    soft_cfm = FloatProperty( name="contact cfm", description="see ode manual" , default=0.00001, min=0.0, max=1.0)

    max_contact_num = IntProperty( name="max number of contacts", description="the maximum number of contact joint each collision can generate" , default=8, min=0)
############################################################################









############################################################################
    def execute(self, context):

        from . import Exporter
        from . import ExporterData
        from . import IDGenerator

        data = ExporterData.ExporterData()

        data.FilePath = self.filepath
        data.UniqueID = IDGenerator.IDGenerator()
        data.VertexID = IDGenerator.IDGenerator()
        data.ooID = IDGenerator.IDGenerator()

        data.UseThreadedManager = self.use_threaded_manager
        data.UseViewer = self.use_viewer
        data.UseGame = self.use_game

        data.MaxAnisotropy = self.max_anisotropy

        data.ERP = self.erp
        data.CFM = self.cfm

        data.StopERP = self.stop_erp
        data.StopCFM = self.stop_cfm

        data.SoftERP = self.soft_erp
        data.SoftCFM = self.soft_cfm
        data.MaxContactNum = self.max_contact_num

        exporter = Exporter.Exporter(data)

        return exporter.export()
############################################################################




# ........................................................................ #
############################################################################




############################################################################
# ........................................................................ #
def menu_func_export(self, context):
    self.layout.operator(ExportOSGT.bl_idname, text = "ooEngine (.osgt)")




def register():
    bpy.utils.register_module(__name__)

    bpy.types.INFO_MT_file_export.append(menu_func_export)




def unregister():
    bpy.utils.unregister_module(__name__)

    bpy.types.INFO_MT_file_export.remove(menu_func_export)




if __name__ == "__main__":
    register()
# ........................................................................ #
############################################################################
